<!-- Student_FreeCourseChapterListNew.html -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>自由课程章节列表</title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
		<link rel="stylesheet" href="../../css/base.css"/>
		<!--<link rel="stylesheet" href="../../css/CFNetPP_Base.css">-->
		<style type="text/css" media="screen">
			.noSign {
				width: auto;
			}
			.loadFailure {
				width: auto;
			}
			.chapter_cell_left_icon {
				height: 16px;
				margin-left: 10px;
				margin-right: 10px;
				/*display:block;*/
			}
			.weui_cell:before {
				left: 0;
			}
			.big_chapter_div {
				margin-top: 10px;
			}
			.weui_panel {
				margin-top: 0;
			}
			.weui_cell {
				background-color: white;
			}
			.fen_ge_xian {
				padding: 1px;
			}
			.chapter_title {
				margin-left: 4px;
			}
		</style>
	</head>
	<body>
		<div class="noSign noDataDiv" hidden="hidden" id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure noInternetDiv" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button" class="mui-btn mui-btn-outlined" onclick="loadData()">
				重新加载
			</button>
		</div>
		<div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
		<div class="base_navigation_bar base_style_color">
			<a class="base_left_item" href="#" onclick="backClick()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span id="tilte"></span>
		</div>
		<div class="weui_panel bgcolor " style="margin-top: 22px">
			<div id="free_chapter_content">
				<!-- <div class="weui_cell big_chapter_div ">
				<div class="weui_cell_bd weui_cell_primary ">
				<p class="base_dark_grey base_content_font">
				<span>第1章</span>
				<span>入库课程介绍</span>
				</p>
				</div>
				</div>
				<div class="weui_cell fen_ge_xian">
				</div>
				<div>
				<div class="weui_cell">
				<div class="weui_cell_hd">
				<img src="../../image/icon_ceyan.png" alt="" class="chapter_cell_left_icon">
				</div>
				<div class="weui_cell_bd weui_cell_primary">
				<p class="base_grey base_tag_font">
				<span>(1.1)</span>
				<span>测验入库互动资源</span>
				</p>
				</div>
				</div>
				<div class="weui_cell">
				<div class="weui_cell_hd">
				<img src="../../image/icon_taolun.png" alt="" class="chapter_cell_left_icon">
				</div>
				<div class="weui_cell_bd weui_cell_primary">
				<p class="base_grey base_tag_font">
				<span>(1.2)</span>
				<span>测验入库互动资源</span>
				</p>
				</div>
				</div>
				</div> -->
			</div>
		</div>
	</body>
	<script src="../../script/jquery.min.js"></script>
	<script src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript">
		var chapterArr = new Array();
		var subChapterObjc = new Object();
		var message;
		apiready = function() {
			loadChapterData();
			if (api.pageParam.openType == "skillCourse") {//技能课程
				message = "学习技能课程" + "《" + api.pageParam.cdetailtitle + "》" + "</br>" + api.pageParam.quarter_name + "认证";
				SendBehaviorTrajectoriesNotifi_Authentication('0', '技能课程列表详情页', '130', api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname, document.title, message);
			} else if (api.pageParam.openType == "vocation") {//职业课程
				message = "学习职业道德" + "《" + api.pageParam.coursename + "》" + "</br>" + api.pageParam.quarter_name + "认证";
				SendBehaviorTrajectoriesNotifi_Authentication('0', '技能课程列表详情页', '136', api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname, document.title, message);
			}
		}
		//加载章节数据
		function loadChapterData() {
			var params = {
				cid : api.pageParam.courseid,//2291 9729
				// cid : 10110//9478
			};
			//		var freeChapterUrl = "http://base.cfnet.org.cn/course/course_normal/getChapterList";
			cfnetppPOST(url_freeChapterUrl, params, true, function(data, status) {
				if (status == 'success') {
					if (data.status == true) {
						var chapterlist = data.data;
						if (chapterlist != null && chapterlist.constructor == Array && chapterlist.length > 0) {//判断章节数组是否有效
							chapterArr = chapterlist;
							$('#tilte').text(chapterlist[0].cdetailtitle);
							setupChapterList();
							//设置章节列表
							$('.noDataDiv').hide();
							$('.noInternetDiv').hide();
						} else {
							$('.noDataDiv').show();
							$('.noInternetDiv').hide();
						}
					} else {
						api.toast({
							msg : '自由课程章节列表加载失败'
						});
						$('.noDataDiv').show();
						$('.noInternetDiv').hide();
					}
				} else {
					api.toast({
						msg : '自由课程章节列表加载失败'
					});
					$('.noDataDiv').hide();
					$('.noInternetDiv').show();
				}
			});
		}

		//设置子章节
		function setupChildChapterList(prefix, chapterid) {
			var params = {
				cid : api.pageParam.courseid, //2291 9729
				// cid : 10110,//9478
				pid : chapterid,
				uid : $api.getStorage('cfnetppuid'),
				jhid : api.pageParam.pid,
			};
			//		var subChapterUrl = "http://base.cfnet.org.cn/course/course_normal/getChapterChildList";
			cfnetppPOST(url_subChapterUrl, params, true, function(data, status) {
				if (status == 'success') {
					if (data.status == true) {
						var chapterlist = data.data;
						if (chapterlist != null && chapterlist.constructor == Array && chapterlist.length > 0) {//判断章节数组是否有效
							setupSubChapterList(prefix, chapterlist);
							//设置子章节列表
						}
					} else {
						//					api.toast({
						//					    msg: '自由课程章节列表加载失败'
						//					});
					}
				} else {
					//				api.toast({
					//				    msg: '自由课程章节列表加载失败'
					//				});
				}
			});
		}

		//设置章节列表
		function setupChapterList() {
			$('#free_chapter_content').html('');
			for (var i = 0; i < chapterArr.length; i++) {
				var chapterData = chapterArr[i];
				var chapterHtmlStr = sectionHtmlWithData(i + 1, chapterData);
				$('#free_chapter_content').append(chapterHtmlStr);
				//拼接章html串
				// loadSubChapterData(i+1, chapterData.id);//根据章id加载子章节数据
				if (parseInt(chapterData.child) > 0) {
					setupChildChapterList(i + 1, chapterData.id);
				}
			}
		}

		//设置子章节列表
		function setupSubChapterList(prefix, chapterlist) {
			// var chapterContainerId = '#container' + chapterlist[0].id;
			var subChapterHtmlStr = '';
			for (var i = 0; i < chapterlist.length; i++) {
				var chapterData = chapterlist[i];
				subChapterObjc[chapterData.id] = chapterData;
				// if (chapterData.content_type != 'tag') {
				subChapterHtmlStr += cellHtmlWithData(prefix, i + 1, chapterData);
				// }
				if (parseInt(chapterData.child) > 0) {
					setupChildChapterList(prefix + '.' + (i + 1), chapterData.id);
				}
			}
			// $(chapterContainerId).html(subChapterHtmlStr);
			$('#' + chapterData.pid).after(subChapterHtmlStr);
			setSubChapterClick();
		}

		function sectionHtmlWithData(index, data) {
			var trainsObj = new GB2312UTF8();
			return '<div id="' + data.id + '" class="weui_cell big_chapter_div top_44">' + '<div class="weui_cell_bd weui_cell_primary top_44">' + '<p class="base_dark_grey base_content_font">' + '<span>第' + index + '章</span>' + '<span class="chapter_title">' + trainsObj.Utf8ToGb2312(data.cdetailtitle) + '</span>' + '</p>' + '</div>' + '</div>' + '<div class="weui_cell fen_ge_xian"></div>';
			// +
			// '<div id="container'+data.id+'"></div>';
		}

		function cellHtmlWithData(prefix, index, data) {
			// alert('prefix:' + prefix + '\n' + 'index:' + index + '\n' + 'data' + JSON.stringify(data));
			var content_type = data.content_type;
			var imgSrc = '';
			if (content_type == 'richtext') {//富文本
				if (data.rid == '') {//富文本
					imgSrc = '../../image/icon_tuwen.png';
				} else {//视频
					imgSrc = '../../image/icon_ship.png';
				}
			} else if (content_type == 'survey') {//调查
				imgSrc = '../../image/icon_diaocha.png';
			} else if (content_type == 'tests') {//测验
				imgSrc = '../../image/icon_ceyan.png';
			} else if (content_type == 'discuss') {//讨论
				imgSrc = '../../image/icon_taolun.png';
			} else if (content_type == 'works') {//作业
				imgSrc = '../../image/icon_zuoye.png';
			} else if (content_type == 'folder') {//文件夹
				imgSrc = '../../image/icon_wenjianjia.png';
			} else if (content_type == 'files') {//文件
				imgSrc = '../../image/icon_wenjia01.png';
			} else if (content_type == 'sitenow') {//现场实操
				imgSrc = '../../image/icon_xianchangshicao.png';
			} else if (content_type == 'hdresource') {//互动资源
				imgSrc = '../../image/icon_hudong.png';
			} else if (content_type == 'sysdeal') {//系统处理
			} else if (content_type == 'flash') {//flash动画
			} else if (content_type == 'tag') {
				imgSrc = '../../image/icon_biaoqian.png';
			}
			return '<div id="' + data.id + '" class="weui_cell sub_chapter_cell" >' + '<div class="weui_cell_hd">' + '<img src="' + imgSrc + '" alt="" class="chapter_cell_left_icon">' + '</div>' + '<div class="weui_cell_bd weui_cell_primary">' + '<p class="base_grey base_tag_font">' + '<span>(' + prefix + '.' + index + ')</span>' + '<span class="chapter_title">' + data.cdetailtitle + '</span>' + '</p>' + '</div>' + '</div>';
		}

		function setSubChapterClick() {
			$('.sub_chapter_cell').unbind('click');
			$('.sub_chapter_cell').click(function() {
				var chapterid = $(this).attr('id');
				var subChapterData = subChapterObjc[chapterid];
				pushToNextWindow(subChapterData);
			});
		}

		//根据类型跳转页面
		function pushToNextWindow(data) {
			var pid = 0;
			var cType = data.content_type;
			var winName = '';
			var pageParam = new Object();
			if (cType == 'richtext') {//富文本
				if (data.rid == '') {//富文本
					winName = '../Study/studyCourseRichtextNew';
					pageParam = {
						chapterid : data.id,
						title : data.cdetailtitle,
						richtextType : 1,
						other : data.other,
					};
				} else {
					winName = 'Student_FreeCourseVideo';
					pageParam = {
						videourl : data.rid,
						videoname : data.cdetailtitle
					};
				}
			} else if (cType == 'survey') {//调查
				winName = '../Study/New_Student_Study_ResearchWindow';
				pageParam = {
					chapterid : data.id,
					pid : pid,
					cid : data.cid,
					title : data.cdetailtitle,
					rid : data.rid,
					bewrite : data.bewrite
				};
			} else if (cType == 'tests') {//测验
				if (data.is_cy == 1) {
					if (data.is_cypass == 1) {
						winName = '../Study/New_student_study_freecourse_TestScore';
					} else {
						winName = '../Study/New_student_study_freecourse_TestExam';
					}
				} else {
					winName = '../Study/New_student_study_freecourse_TestExam';
				}
				pageParam = {
					chapterid : data.id,
					pid : pid,
					cid : data.cid,
					title : data.cdetailtitle,
					rid : data.rid,
					bewrite : data.bewrite
				};
			} else if (cType == 'discuss') {//讨论
				winName = '../Study/New_Student_FreeCourse_DiscussChapterWindow';
				pageParam = {
					chapterid : data.id,
					pid : pid,
					cid : data.cid,
					title : data.cdetailtitle,
					bewrite : data.bewrite
				};
			} else if (cType == 'works') {//作业
				winName = '../Study/new_student_study_freecourse_homeworks';
				pageParam = {
					pid : pid,
					chapterid : data.id
				};
			} else if (cType == 'folder') {//文件夹
				winName = '../Study/Student_FreeCourseFileNew';
				pageParam = data;
			} else if (cType == 'files') {//文件
				winName = '../Study/Student_FreeCourseFileNew';
				pageParam = data;
			} else if (cType == 'sitenow') {//现场实操
				winName = '../Study/new_Cfeval_task';
				pageParam = data;
				pageParam["pid"] = pid;
			} else if (cType == 'hdresource') {//互动资源
				winName = 'Interactive_Chapter_Window';
				pageParam = {
					hdresourceType : 1,
					type : 2,
					id : api.pageParam.courseid,
					cid : data.cid,
					pid : data.pid,
					planid : pid,
					cdetailtitle : api.pageParam.cdetailtitle,
					bewrite : api.pageParam.bewrite,
					rid : data.rid//互动资源id
				};
				//只针对49 初级车管师,中级车管师, 高级车管,车管专家4个岗位使用新版互动资源
				if (api.pageParam.hasOwnProperty("quarter_id") && (api.pageParam.quarter_id == 49 || api.pageParam.quarter_id == 50 || api.pageParam.quarter_id == 51 || api.pageParam.quarter_id == 52)) {
					pageParam["hdresourceType"] = 0;
					pageParam["id"] = data.rid;
				}
				if (api.connectionType == 'none') {
					api.toast({
						msg : '暂无网络，无法访问该内容'
					});
					return;
				}
			}
			api.openWin({useWKWebView:true,
				name : winName,
				url : winName + '.html',
				pageParam : pageParam
			});
		}

		function backClick() {
			if (api.pageParam.openType == "skillCourse") {//技能课程
				message = "学习技能课程" + "《" + api.pageParam.cdetailtitle + "》" + "</br>" + api.pageParam.quarter_name + "认证";
				SendBehaviorTrajectoriesNotifi_Authentication('1', '技能课程列表详情页', '130', api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname, document.title, message);
			} else if (api.pageParam.openType == "vocation") {//职业课程
				message = "学习职业道德" + "《" + api.pageParam.coursename + "》" + "</br>" + api.pageParam.quarter_name + "认证";
				SendBehaviorTrajectoriesNotifi_Authentication('1', '技能课程列表详情页', '136', api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname, document.title, message);
			}
			api.closeWin({});
		}
	</script>
</html>